<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p>新增车辆</p>
      </div>
      <div class="right-box">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="table-box">
        <div style="display:flex">
          <div class="item-box">
            <div class="number-box">车牌号</div>
            <div class="number1-box">
              <el-input v-model="item.carNumber" style="width:60%;" placeholder="请输入用品名称"></el-input>
            </div>
          </div>
          <div class="item-box">
            <div class="number-box">颜色</div>
            <div class="number1-box">
              <el-input v-model="item.carColor" style="width:60%;" placeholder="请输入用品单位"></el-input>
            </div>
          </div>
        </div>
        <div style="display:flex">
          <div class="item-box">
            <div class="number-box">品牌</div>
            <div class="number1-box">
              <el-input v-model="item.carBrand" style="width:60%;" placeholder="请输入用品名称"></el-input>
            </div>
          </div>
          <div class="item-box">
            <div class="number-box">型号</div>
            <div class="number1-box">
              <el-input v-model="item.carType" style="width:60%;" placeholder="请输入用品单位"></el-input>
            </div>
          </div>
        </div>
        <div style="display:flex">
          <div class="item-box">
            <div class="number-box">保险时间</div>
            <div class="number1-box">
              <el-date-picker v-model="item.insuranceDate" style="width:60%;"></el-date-picker>
            </div>
          </div>
          <div class="item-box">
            <div class="number-box">年检时间</div>
            <div class="number1-box">
              <el-date-picker v-model="item.yearlyDate" style="width:60%;"></el-date-picker>
            </div>
          </div>
        </div>
        <div style="display:flex">
          <div class="item-box">
            <div class="number-box">购买时间</div>
            <div class="number1-box">
              <el-date-picker v-model="item.buyTime" style="width:60%;"></el-date-picker>
            </div>
          </div>
          <div class="item-box">
            <div class="number-box">报废时间</div>
            <div class="number1-box">
              <el-date-picker v-model="item.scrapDate" style="width:60%;"></el-date-picker>
            </div>
          </div>
        </div>
        <div style="display:flex">
          <div class="item-box">
            <div class="number-box">公里数</div>
            <div class="number1-box">
              <el-input v-model="item.thisLong" style="width:60%;" placeholder="请输入用品名称"></el-input>
            </div>
          </div>
          <div class="item-box">
            <div class="number-box">提前提醒</div>
            <div class="number1-box">
              <el-select v-model="value" placeholder="请选择" style="width:60%;" @change="change">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </div>
          </div>
        </div>
      </div>
      <div class="btn-box">
        <el-button type="primary" @click="addlist()">确定</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data () {
    return {
      item: { carNumber: "", carColor: "", carBrand: "", carType: "", insuranceDate: "", yearlyDate: "", buyTime: "", scrapDate: "", thisLong: "", earlyWarning: 1, creater: 0 },
      options: [{ value: 1, label: "7天" }, { value: 2, label: "15天" }, { value: 3, label: "30天" },],
      Mark: 0,
      value: "7天",
      creater: 0
    };
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
  },
  methods: {
    Return () {
      window.history.go(-1);
    },
    change (e) { this.item.earlyWarning = e; console.log(this.item) },
    addlist () {
      if (this.Mark == 0) {
        this.item.creater = this.creater;
        if (this.item.carNumber == "") { this.$message.error("车牌号非空"); return; }
        if (this.item.carColor == "") { this.$message.error("颜色非空"); return; }
        if (this.item.carBrand == "") { this.$message.error("品牌非空"); return; }
        if (this.item.carType == "") { this.$message.error("型号非空"); return; }
        if (this.item.insuranceDate == "") { this.$message.error("保险日期非空"); return; }
        if (this.item.yearlyDate == "") { this.$message.error("年检日期非空"); return; }
        if (this.item.buyTime == "") { this.$message.error("购买时间非空"); return; }
        if (this.item.scrapDate == "") { this.$message.error("报废日非空"); return; }
        if (this.item.thisLong == "") { this.$message.error("公里数非空"); return; }
        var objs = JSON.stringify(this.item); let the = { index: 3, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip); this.Mark = 0;
          }
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.left-box {
  width: 100px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
  // border: 1px solid red;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  width: 90px;
  height: 40px;
  margin-right: 2%;
  border-radius: 8px;
  margin-top: 10px;
  background-color: $return-color;
  // border: 1px solid red;
}
.right-box:hover {
  background-color: #a4a6ad;
}
.right-box span {
  float: left;
  color: $white;
  font-size: $font-size-medium;
  line-height: 40px;
  //  border: 1px solid red;
}
.right-box img {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box {
  width: 98%;
  height: 600px;
  margin: 0 auto;
  border-radius: 2px;
  background-color: $white;
  text-align: center;
  padding-top: 100px;
}
.table-box {
  width: 70%;
  margin: 0 auto;
  border: 1px solid $bordercolor;
}
.item-box {
  width: 100%;
  height: 60px;
  display: flex;
  border-bottom: 1px solid $bordercolor;
  margin-bottom: -1px;
}
.number-box {
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
  border-left: 1px solid $bordercolor;
  margin-left: -1px;
}
.number3-box {
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.number1-box {
  flex: 1;
  // text-align: center;

  line-height: 55px;
}
.btn-box {
  width: 20%;
  height: 60px;
  margin: 0 auto;
  padding-left: 80px;
  margin-top: 40px;
  // border: 1px solid red;
}
</style>
